module my_type
  implicit none
  type :: person
     integer :: age
     character(len=20) :: name
  end type person
end module my_type

module interface_
  interface
     subroutine prnt(arr)
     implicit none
     real, dimension(:,:), intent(in) :: arr
   end subroutine prnt
end interface
end module interface_


     


subroutine prnt(arr)
  implicit none
  real, dimension(:,:), intent(in) :: arr
  integer :: row, col
  row = size(arr, 1)
  col = size(arr, 2)
  write(*,*) row, col
end subroutine prnt


program test
  use my_type
  use interface_
  real, allocatable, dimension(:,:) :: array
  real, allocatable, dimension(:,:) :: arr2
  integer :: k, dim, status
  character(len=20) :: fname
  real :: a = 0.0
  type(person) :: ding = person(21, 'ding xuejun')
  integer :: i = 1, j = 3
  character(len=20) :: string = 'ding xuejun'
  real, dimension(2) :: arr1 = (/1.0, 2.0/)
  namelist /mylist/ i, j, string


  real, target :: b, c
  real, pointer :: pb, pc
  real, dimension(:), pointer :: pd
  real, dimension(2) :: m1=(/1.0, 2.0/), m2 = (/3.0, 2.0/)
  write(*,*) m1*m2
  stop
  allocate(arr2(2,2))
  arr2(1,:) = arr1
  arr2(2,:) = arr1
  write(*,*) size(arr1)
  write(*,*) arr2
  call prnt(arr2)
  stop


  
  b = 1.0; c = 2.0
  pb => b; pc => c
  write(*,*) pb, pc
  pb = pc
  write(*,*) pb
  c = 9.0
  pb => c
  pc => pb
  write(*,*)  pc
  allocate(pc)
  pc = pb
  write(*,*)  pc
  deallocate(pc)

  allocate(pd(10))
  pd = (/(k*1.0, k = 1, 10)/)
  write(*,*)  pd
  deallocate(pd)
  stop
  

  open(unit=8, file='namelist_out', status='replace', action='write',iostat=status)
  write(8,nml=mylist)
  close(unit=8)
  
  write(*,*) ding
  write(*,*) 'input file name'
  read(*,*) fname

  open(unit=4, file=fname, status='old', action='read', iostat=status)
  if(status /= 0) then
     write(*,*) 'open file fail'
     stop
  end if
  
  read(4,*) dim
  allocate(array(dim,dim), stat=status)
  if(status /= 0) then
     write(*,*) 'allocate fail'
     stop
  else
     do k = 1,dim
        read(4,*) array(k,:)
     end do
  end if

  open(unit=10, file='unformat.dat', status='replace', action='write',form='unformatted', iostat=status)
  write(10) array
  close(unit=10)
  close(unit=4)

  open(unit=5, file='format.dat', status='new', action='write', iostat=status)
  write(5, fmt=100) arr1
100 format(1x,2F10.5)
  close(5)
  deallocate(array)

  do k = 10,10
     write(*,*) k
  end do

  k = -10
  write(*,*) abs(k)

  write(*,*)
  write(*,*) kind(0.0)
  write(*,*) kind(0.0D0)
  write(*,*) kind(a)
  write(*,*) kind(0)
  
end program test
